package com.bb.flow.parser.impl.parsejson.parsenode;

import com.alibaba.fastjson2.JSONObject;
import com.bb.flow.api.exception.ParseException;
import com.bb.flow.config.ClassInfo;
import com.bb.flow.config.ConditionInfo;

/**
 * @author bigbeard
 * 解析条件
 */
public class ParseCondition {

    /**
     * 类解析器
     */
    private ParseClassInfo parseClassInfo;

    /**
     * 设置解析类的解析器
     *
     * @param parseClassInfo 类解析器
     */
    public void setParseClassInfo(ParseClassInfo parseClassInfo) {
        this.parseClassInfo = parseClassInfo;
    }

    /**
     * 解析条件
     *
     * @param jsonObject       待解析JSON 对象
     * @param nodeName         节点名称
     * @param flowTemplateName 流程模版名称
     * @return 条件内容
     */
    public ConditionInfo parseCondition(JSONObject jsonObject, String nodeName, String flowTemplateName) throws ParseException {
        ConditionInfo conditionInfo = new ConditionInfo();
        String composeExpress = jsonObject.getString("ComposeExpress");
        conditionInfo.setComposeExpress(composeExpress);
        JSONObject jsonClassInfo = jsonObject.getJSONObject("ClassInfo");
        if (null != jsonClassInfo) {
            ClassInfo classInfo = parseClassInfo.parseClassInfo(jsonClassInfo, nodeName, flowTemplateName);
            conditionInfo.setClassInfo(classInfo);
        }
        return conditionInfo;
    }
}
